﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Pingy.Commanding;
using System;

namespace App.Test
{


    /// <summary>
    ///This is a test class for DelegateCommandTest and is intended
    ///to contain all DelegateCommandTest Unit Tests
    ///</summary>
    [TestClass()]
    public class DelegateCommandTest
    {
        private TestContext testContextInstance;

        bool executeCalled;
        bool canExecuteCalled;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        [TestInitialize()]
        public void MyTestInitialize()
        {
            canExecuteCalled = false;
            executeCalled = false;
        }
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        public bool CanExecute(object param)
        {
            canExecuteCalled = true;
            return true;
        }

        public void Execute(object param)
        {
            executeCalled = true;
        }

        /// <summary>
        ///A test for CanExecute
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void TestCanExecuteIfParameterIsNotOfTypeT()
        {
            DelegateCommand<string> target = new DelegateCommand<string>
                (
                    new Action<string>(Execute),
                    new Func<string, bool>(CanExecute)
                );
            int parameter = 10; 
            bool expected = false; 
            bool actual = target.CanExecute(parameter);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(false, canExecuteCalled);
        }

       

        /// <summary>
        ///A test for Execute
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void TestExecuteIfParameterIsNotOfTypeT()
        {
            DelegateCommand<string> target = new DelegateCommand<string>
                (
                    new Action<string>(Execute),
                    new Func<string, bool>(CanExecute)
                );
            int parameter = 10;
            target.Execute(parameter);
            Assert.AreEqual(false, executeCalled);
        }
    }
}
